#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

int main() {
  freopen("fairphoto.in", "r", stdin);
  freopen("fairphoto.out", "w", stdout);
  int n;

  cin >> n;
  vector<pair<int, int>> cows(n);

  for (int i = 0; i < n; i++) {
    string type;
    cin >> cows[i].first >> type;
    if (type == "G") {
      cows[i].second = 1;
    } else {
      cows[i].second = -1;
    }
  }
  sort(cows.begin(), cows.end());

  int ans = 0;

  int last = 0;
  for (int i = 1; i < n; i++) {
    if (cows[i].second != cows[i - 1].second) {
      last = i;
    }
    ans = max(ans, cows[i].first - cows[last].first);
  }

  map<int, int> sum2pos;

  int s = 0;

  sum2pos[0] = cows[0].first;
  for (int i = 0; i < n; i++) {
    s += cows[i].second;
    if (sum2pos.count(s)) {
      ans = max(ans, cows[i].first - sum2pos[s]);
    } else if (i + 1 < n && sum2pos.count(s) == 0) {
      sum2pos[s] = cows[i + 1].first;
    }
  }

  cout << ans << '\n';
  return 0;
}